home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / bc_ti.zip / TI705.ASC < prev    next >
Text File  |  1992-02-25  |  2KB  |  133 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  Borland C++                            NUMBER  :  705
  9.   VERSION  :  2.0
  10.        OS  :  DOS
  11.      DATE  :  February 25, 1992                        PAGE  :  1/2
  12.  
  13.     TITLE  :  Allocating More Than 64K of Memory in DOS
  14.  
  15.  
  16.  
  17.  
  18.   /************************************************************************
  19.  
  20.   This program demonstrates the dynamic allocation of a memory
  21.   block larger than 64K bytes using farcalloc().  It should not be
  22.   compiled in the Tiny memory model.  The program calls farcoreleft
  23.   prior to allocating the block of memory to determine how much
  24.   memory is available.  Note that this method will not be accurate
  25.   if memory has been previously allocated and then released as the
  26.   released memory is handled differently. If you choose to run this
  27.   program from inside the integrated development environment you
  28.   must set the head size under OPTIONS/DEBUGGER to at least the
  29.   size of the two parameters passed to farcalloc() + 5 bytes. Also
  30.   note that farcalloc can be interchanged freely with farmalloc or
  31.   farrealloc in this example.
  32.  
  33.   ***********************************************************************/
  34.  
  35.  
  36.   #include <stdio.h>
  37.   #include <alloc.h>
  38.   #include <string.h>
  39.   #include <dos.h>
  40.   #include <conio.h>
  41.  
  42.   int main(void)
  43.   {
  44.      int huge *fptr;
  45.      unsigned long val;
  46.  
  47.      clrscr();
  48.  
  49.      /* Check the amount of memory available if no blocks have been
  50.         freed */
  51.      printf("\nMemory available on the far heap:   %lu\n",val =
  52.              farcoreleft());
  53.  
  54.      /* allocate memory for the far pointer */
  55.      fptr = (int huge *) farcalloc( 66000L, sizeof(int));
  56.  
  57.  
  58.      /* display string (note the F modifier) */
  59.      printf("Address of allocated block is:      %Fp", fptr);
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.   PRODUCT  :  Borland C++                            NUMBER  :  705
  75.   VERSION  :  2.0
  76.        OS  :  DOS
  77.      DATE  :  February 25, 1992                        PAGE  :  2/2
  78.  
  79.     TITLE  :  Allocating More Than 64K of Memory in DOS
  80.  
  81.  
  82.  
  83.  
  84.      /* Check how much memory is left */
  85.      printf("\nMemory left on the far heap:        %lu\n",val =
  86.                farcoreleft());
  87.  
  88.      getch();
  89.  
  90.      /* free the memory */
  91.      farfree((int far *) fptr);
  92.  
  93.      return 0;
  94.   }
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.